package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Order;
import com.zretc.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {

    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;

    @RequestMapping("/getOrderAllDetail")
    @ResponseBody
    public PageInfo<Order> getOrderAllDetail(@RequestParam(value = "pageNum") String pageNum,
                                             @RequestParam(value = "pageSize") String pageSize,
                                             @RequestParam(value = "accountName") String accountName,
                                             @RequestParam(value = "isDelete") String isDelete,
                                             @RequestParam(value = "adminId") String adminId){

        Map<String, String> map=new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("accountName",accountName);
        map.put("isDelete",isDelete);
        map.put("adminId",adminId);
        PageInfo<Order> pageInfo = orderService.getOrderDetail(map);

        logger.info("===="+pageInfo);

        return pageInfo;
    }

    @RequestMapping("/delOrderById")
    @ResponseBody
    public boolean delOrderById(@RequestParam(value = "orderId") String orderId){

        boolean b = orderService.delOrderByOrderId(orderId);

        logger.info("===="+b);

        return b;
    }
    @RequestMapping("/updateStateById")
    @ResponseBody
    public boolean updateStateById(@RequestParam(value = "orderId") String orderId){

        boolean b = orderService.updateStateByOrderId(orderId,2);

        logger.info("===="+b);

        return b;
    }
    @RequestMapping("/getOrderInfo")
    @ResponseBody
    public List<Map<String,Object>> getOrderInfo(@RequestParam(value = "accountId") String accountId){
        List<Map<String,Object>> order =orderService.getOrder(accountId);
        logger.info("===="+order);
        return order;
    }
}
